Julia Quick Start

Download Julia here: https://julialang.org/downloads/

Open the Julia application. You should see a startup banner similar to this:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version x.y.z (YYYY-MM-DD)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

Try typing in 2+2 and hitting enter. If you know LaTeX, Julia is happy to think about LaTeX commands, so try typing in whcih turns into π and hitting enter

Install Visual Studio Code (VS Code)

After confirming Julia runs, download and install VS Code: https://code.visualstudio.com/

  • Open VS Code.
  • Click on the Extensions icon in the Activity Bar on the side of the window. It looks like four squares forming a larger square, with the top-right square slightly detached.
  • Search for “Julia” in the search bar.
  • Find the extension named Julia published by julialang and click Install.

Create and Run Your First Julia File

  • Create a new file named HelloJulia.jl.
  • Open this file in VS Code.
  • Paste the following code into the file:
println("The first digits of pi are: ", pi)
  • Run the code by clicking the Run button (a trinagluar play icon) in the top-right corner of the editor.

Manage Julia Packages

In the VS Code terminal panel where you saw the output, you should see the Julia prompt julia>. Press the ] key (right square bracket). The prompt will change to indicate you are in package mode. To exit Pkg mode and return to the standard julia> prompt, press the Backspace key.

While in Pkg mode, type the following command and press Enter:

add GLMakie CairoMakie DataFrames

Then wait for installation, this can take awhile.

Graph some data

Now you can modify your HelloJulia.jl script (or create a new one) to use these packages. Here’s an example that creates a simple plot using Makie and saves it as a PDF:

using GLMakie, DataFrames # CairoMakie

# Create some sample data
x = 0:0.1:2pi
y_sin = sin.(x)
y_cos = cos.(x)

# Create a DataFrame (optional, but useful to show now rather that later)
df = DataFrame(X=x, SinY=y_sin, CosY=y_cos)

# Create the plot figure and axis
fig = Figure(size = (400, 400))
ax = Axis(fig[1, 1], xlabel = "X [um]", ylabel = "Y [Pa]")

# Plot the lines
lines!(ax, df.X, df.SinY, label = "sin(x)", color = :blue, linewidth = 2)
lines!(ax, df.X, df.CosY, label = "cos(x)", color = :red, linewidth = 2)

axislegend(ax) # Add a legend

# Show the plot in an interactive window
#GLMakie.activate!() 
fig #or display(fig)


# Save the plot as a PDF
#CairoMakie.activate!()
#save("plot.pdf", fig)